from system.action import Action

class ScreenWrap(Action):
    def run(self, args):
        if 'res' in args:
            self.res = args['res']
        else:
            self.resObj = self.object.search(lambda obj: obj.hasVar('res'))
            if self.resObj:
                self.res = self.resObj.getVar("res",(800,600))
            else:
                self.res = 800,600
                
    def receive_time_10(self, args):
        if self.object.hasVar("pos"):
            x,y = self.object.getVar("pos",(0,0))
            change = False
            if x < 0:
                change = True
                x += self.res[0]
            elif x > self.res[0]:
                change = True
                x -= self.res[0]
            if y < 0:
                change = True
                y += self.res[1]
            elif y > self.res[1]:
                change = True
                y -= self.res[1]
            if change:
                self.object.setVar("pos",(x,y))
